package com.jprocms.module.cms.framework.job.util;

import cn.hutool.core.lang.Assert;
import com.jpro.framework.common.util.json.JsonUtils;
import com.jprocms.module.cms.dto.JobParam;
import com.xxl.job.core.context.XxlJobHelper;

/**
 * @author jprocms
 */
public class XxlJobUtil {

    public static String parseToXxlParam(Long id, String param) {
        Assert.notNull(id, "任务id不能为空");
        return JsonUtils.toJsonString(new JobParam(id, param));
    }

    public static JobParam getJobParam() {
        String param = XxlJobHelper.getJobParam();
        if (param == null) {
            return null;
        }
        return JsonUtils.parseObject(param, JobParam.class);
    }

    public static String getBussinessParam() {
        String param = XxlJobHelper.getJobParam();
        if (param == null) {
            return null;
        }
        JobParam JobParam = JsonUtils.parseObject(param, JobParam.class);
        return JobParam == null ? null : JobParam.getParam();
    }
}
